<?
if (isset($_POST['btnsubmit'])) {
    require("required/dbconnect.php");
    require("required/function.php");
    require("required/email.php");

    $verycode = $_POST['verification_code'];


    if ($verycode != $_SESSION['verycode']) {
        header("Location:os_paymentselect.php?c=3");
        die();
    }


    $name = $_POST['name'];
    $hpnumber = $_POST['hpnumber'];

    $address1 = $_POST['address1'];
    $address2 = $_POST['address2'];
    $postcode = $_POST['postcode'];
    $country = $_POST['country'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $email = $_POST['email'];
    $message = mysql_escape_string($_POST['message']);

    $invoice_number = "DO" . date("Ymdhms");
    $service_preferred = $_POST['service_preferred'];
    $regisdate = date('Y-m-d');

    $chk = mysql_query("select count(*) as result from os_bill_details where invoice_number='$invoice_number'");
    if (mysql_result($chk, 0, "result") > 0) {
        header("Location:os_mybill.php");
    } else {
        $chk_email = mysql_query("select id from os_member where email='$email'");

        if (mysql_num_rows($chk_email) == 0) {
            $insert = mysql_query("insert into os_member(email,name,hpnumber,address1,address2,postcode,city,state,country,registerdate,status,service_preferred,purchase_remarks)
			 values('$email','$name','$hpnumber','$address1','$address2','$postcode','$city','$state','$country','$regisdate','inactivate','$service_preferred','$message')") or die(mysql_error());

            $get_new_id = mysql_query("select id from os_member where email='$email' order by id desc limit 1");
            $get_id = mysql_result($get_new_id, 0, "id");
        } else {
            $get_id = mysql_result($chk_email, 0, "id");
            $update = mysql_query("update os_member set name='$name',hpnumber='$hpnumber',address1='$address1',address2='$address2',postcode='$postcode',city='$city',state='$state',country='$country',service_preferred='$service_preferred',purchase_remarks='$message' where id=$get_id") or die(mysql_error());
        }

        $insert = mysql_query("insert into os_bill_details(uid,receiver_name,create_date,invoice_number,service_preferred ,address1,address2,postcode,city,country,state,contact_number,email,message,verified_date)							values($get_id,'$name',now(),'$invoice_number','$service_preferred','$address1','$address2','$postcode','$city','$country','$state','$hpnumber','$email','$message',now())");

        $get_bill = mysql_query("select * from os_bill_details where email='$email' order by id desc limit 1");

        $b = mysql_fetch_array($get_bill, MYSQL_ASSOC);



        $totalamount = 0;

        foreach ($_SESSION['cart'] as $cartItems) {
            $total = 0;
            $itemId = $cartItems['id'];
            $qty = $cartItems['quantity'];


            $get_item = mysql_query("select pid, unit_price from os_product_inventory where id=$itemId") or die(mysql_error());
            $insert = mysql_query("insert into os_bill_items(bid,pid,price,quantity)values(" . $b['id'] . "," . mysql_result($get_item, 0, "pid") . "," . mysql_result($get_item, 0, "unit_price") . "," . $qty . ")");
            $total = $qty * mysql_result($get_item, 0, "unit_price");
            $totalamount = $totalamount + $total;
        }

        $update = mysql_query("update os_bill_details set status=1,total_amount=$totalamount where id=" . $b['id']);

        //email_purchase_notice($b['id']);
        //email_orderrequest($b['id']);
        unset($_SESSION['cart']);
        header("Location:os_paymentselect.php?c=1&id=" . $b['id']);
    }
}

$accesslevel = 1;
$title = "Billing ";
require("required/dbconnect.php");


if (!empty($_SESSION['loginid'])) {
    $get_data = mysql_query("select * from os_member where id=" . $_SESSION['loginid']) or die(mysql_error());
    $rd = mysql_fetch_array($get_data, MYSQL_ASSOC);

    $name = $rd['name'];
    $hpnumber = $rd['hpnumber'];
    $address1 = $rd['address1'];
    $address2 = $rd['address2'];
    $postcode = $rd['postcode'];


    if ($rd['country'] == "") {
        $country = "";
    } else {
        $chk_country = mysql_query("select * from os_country where id='" . $rd['country'] . "'");

        if (mysql_num_rows($chk_country) == 0) {
            $country = "";
        } else {
            $country = mysql_result($chk_country, 0, "id");
        }
    }

    if ($rd['state'] == "") {
        $state = "";
    } else {
        $chk_state = mysql_query("select * from os_state where id='" . $rd['state'] . "'");

        if (mysql_num_rows($chk_state) == 0) {
            $state = "";
        } else {
            $state = mysql_result($chk_state, 0, "id");
        }
    }

    if ($rd['service_preferred'] == "") {
        $service_preferred = "";
    } else {
        $chk_service_preferred = mysql_query("select * from os_shipping_company where id='" . $rd['service_preferred'] . "'");

        if (mysql_num_rows($chk_service_preferred) == 0) {
            $service_preferred = "";
        } else {
            $service_preferred = mysql_result($chk_service_preferred, 0, "id");
        }
    }


    $city = $rd['city'];

    $email = $rd['email'];
    $service_preferred = $rd['service_preferred'];
    $message = $rd['purchase_remarks'];
    $found = -2;
} else {
    if (!empty($_GET['email'])) {
        $email = $_GET['email'];
        $chk_email = mysql_query("select * from os_member where email='$email'") or die(mysql_error());

        if (mysql_num_rows($chk_email) > 0) {
            $rd = mysql_fetch_array($chk_email, MYSQL_ASSOC);

            $name = $rd['name'];
            $hpnumber = $rd['hpnumber'];
            $address1 = $rd['address1'];
            $address2 = $rd['address2'];
            $postcode = $rd['postcode'];

            $city = $rd['city'];
            if ($rd['country'] == "") {
                $country = "";
            } else {
                $chk_country = mysql_query("select * from os_country where id='" . $rd['country'] . "'");

                if (mysql_num_rows($chk_country) == 0) {
                    $country = "";
                } else {
                    $country = mysql_result($chk_country, 0, "id");
                }
            }

            if ($rd['state'] == "") {
                $state = "";
            } else {
                $chk_state = mysql_query("select * from os_state where id='" . $rd['state'] . "'");

                if (mysql_num_rows($chk_state) == 0) {
                    $state = "";
                } else {
                    $state = mysql_result($chk_state, 0, "id");
                }
            }

            if ($rd['service_preferred'] == "") {
                $service_preferred = "";
            } else {
                $chk_service_preferred = mysql_query("select * from os_shipping_company where id='" . $rd['service_preferred'] . "'");

                if (mysql_num_rows($chk_service_preferred) == 0) {
                    $service_preferred = "";
                } else {
                    $service_preferred = mysql_result($chk_service_preferred, 0, "id");
                }
            }

            $email = $rd['email'];

            $message = $rd['purchase_message'];
            $found = 1;
        } else {
            $name = "";
            $hpnumber = "";
            $address1 = "";
            $address2 = "";
            $postcode = "";
            $country = "";
            $city = "";
            $state = "";
            $email = "";
            $service_preferred = "";
            $message = "";
            $found = 0;
        }
    } else {
        $name = "";
        $hpnumber = "";
        $address1 = "";
        $address2 = "";
        $postcode = "";
        $country = "";
        $city = "";
        $state = "";
        $email = "";
        $service_preferred = "";
        $message = "";
        $found = -1;
    }
}

require("required/share_function.php");
require("required/header.php");
?>
<script language="JavaScript" type="text/javascript" src="required/js/goAjax.js"></script>
<script type="text/javascript" src="required/calendarDateInput.js">
</script>

<script language="javascript">
    
	
    function checkExist(field,divName,showName) 
    {
        var value = document.getElementById(field).value;
        if(value!=""){
            changeContent('required/js/checkExist.php?field='+field+'&value='+value+"&showName="+showName,divName)
        }
    }
	
    function changeState(countryId) 
    {
        if(countryId!=""){
            changeContent('required/js/ajax_place.php?country_id='+countryId+'&tag=state&getshipping=1','divState');
			
        }
    }
	
    function changeShippingCompany(countryId) 
    {
        if(countryId!=""){
            changeContent('required/js/ajax_shipping_company.php?country_id='+countryId+'&tag=state&getshipping=1','divShippingCompany');
            setTimeout("getShipping()",400);
        }
    }
	
	
    function getShipping() 
    {			
        var state=document.getElementById("state").value
        var country=document.getElementById("country").value
        var service_preferred = document.getElementById("service_preferred").value;
        changeContent('required/js/getShipping.php?country_id='+country+'&state_id='+state+'&shipping_id='+service_preferred,'divShipping');
		
    }
	
    function getAreaType(countryId) 
    {
        changeContent('required/js/getAreaType.php?country_id='+countryId,'divAreaType');
				
    }
	
	
    function retrievePassword() {
        var value = document.getElementById("retrievepwd_email").value;
		
        if(value!=""){
            changeContent('os_ajax_forgotpwd2.php?email='+value,'divForgotPwdResult')
        }
    }
	
    function validateVoucher() {
        var value = document.getElementById("discount_voucher").value;
		
        if(value!=""){
            changeContent('required/js/validateVoucher.php?value='+value,"divVoucher")
        }
    }
	
    function pwdFormValidate(frm)
    {
        if(document.frm1.oldpassword.value=="")
        {
            alert("Please enter old password");
            document.frm1.oldpassword.focus();
            return false;
        }
        if(document.frm1.newpassword.value=="")
        {
            alert("Please enter new password");
            document.frm1.newpassword.focus();
            return false;
        }
        if(document.frm1.cnewpassword.value=="")
        {
            alert("Please confirm new password");
            document.frm1.cnewpassword.focus();
            return false;
        }
        if(document.frm1.cnewpassword.value!=document.frm1.newpassword.value)
        {
            alert("Password not match,please check again");
            document.frm1.cnewpassword.focus();
            return false;
        }
        return true;
    }
	
    function formvalidate1(frm1)
    {
		
        if(document.frm1.email.value=="")
        {
            alert("Please enter your email");
            document.frm1.email.focus();
            return false;
        }
        if (document.frm1.email.value!="")
        {
            var x = document.frm1.email.value;
            var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (filter.test(x)==false)
            { 
                alert('Please enter a valid email address');
                document.frm1.email.focus();
                return false;
            }
		
        }
        if(document.frm1.password.value=="")
        {
            alert("Please enter password");
            document.frm1.password.focus();
            return false;
        }
        if(document.frm1.password.value.length<6)
        {
            alert("password length must more than 6 characters");
            document.frm1.password.focus();
            return false;
        }
        if(document.frm1.password.value.indexOf(" ")>-1)
        {
            alert("spaces not allowed!");
            document.frm1.password.focus();
            return false;
        }
        if(document.frm1.cpassword.value=="")
        {
            alert("Please reenter your password");
            document.frm1.cpassword.focus();
            return false;
        }
        if(document.frm1.password.value!=document.frm1.cpassword.value)
        {
            alert("Password doesn't match, please check");
            document.frm1.cpassword.focus();
            return false;
        }
        if(document.frm1.name.value=="")
        {
            alert("Please enter your name");
            document.frm1.name.focus();
            return false;
        }
        if(document.frm1.hpnumber.value=="")
        {
            alert("Please enter your contact number");
            document.frm1.hpnumber.focus();
            return false;
        }
        if(document.frm1.service_preferred.value=="")
        {
            alert("Please preferred service");
            document.frm1.service_preferred.focus();
            return false;
        }
		
        if(document.frm1.address1.value=="")
        {
            alert("Please enter your address");
            document.frm1.address1.focus();
            return false;
        }
        if(document.frm1.email.value=="")
        {
            alert("Please enter your email");
            document.frm1.email.focus();
            return false;
        }
        if(document.frm1.email.value!="")
        {
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            var address = document.frm1.email.value;
            if(reg.test(address) == false) {
                alert("Invalid email");
                document.frm1.email.focus();
                return false;
            }
        }
		
        if(document.frm1.verification_code.value=="")
        {
            alert("Please enter verification_code");
            document.frm1.verification_code.focus();
            return false;
        }
		
        return true;
    }
	
    function formvalidate2(frm1)
    {
        if(document.frm1.name.value=="")
        {
            alert("Please enter your name");
            document.frm1.name.focus();
            return false;
		
        }
        if(document.frm1.hpnumber.value=="")
        {
            alert("Please enter your contact number");
            document.frm1.hpnumber.focus();
            return false;
        }
        if(document.frm1.service_preferred.value=="")
        {
            alert("Please preferred service");
            document.frm1.service_preferred.focus();
            return false;
        }
        if(document.frm1.address1.value=="")
        {
            alert("Please enter your address");
            document.frm1.address1.focus();
            return false;
        }
		
        if(document.frm1.email.value=="")
        {
            alert("Please enter your email");
            document.frm1.email.focus();
            return false;
        }
        if(document.frm1.email.value!="")
        {
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            var address = document.frm1.email.value;
            if(reg.test(address) == false) {
                alert("Invalid email");
                document.frm1.email.focus();
                return false;
            }
        }
        if(document.frm1.verification_code.value=="")
        {
            alert("Please enter verification_code");
            document.frm1.verification_code.focus();
            return false;
        }
		
		
        return true;
    }
	
    function retrieveData(email)
    {
        var email=document.frm1.email.value;
		
        window.location="os_bill.php?email="+email;
		
    }
	
	
</script>



<table width="100%" cellpadding="5" cellspacing="0">
    <tr>
        <td align="left" class="page_title_bar" colspan="3" height="30">
            Checkout
        </td>

    </tr>	
    <?
    if ($header_total_items == 0) {
        ?>
        <tr>
            <Td colspan="3" height="300" valign="top"><div class="dw_failed">Invalid!</div></Td>
        </tr>
        <?
    } elseif ($_SESSION['total_items'] > $max_item) {
        ?>
        <tr>
            <Td colspan="3" align="center"><img src="images/icons/cross.jpg" align="absmiddle"> Sorry, the maximum items for one transaction must be less than 120.(you have <?= $_SESSION['total_items'] ?> items in your cart) <input type="button" value="Back to cart" onClick="window.open('os_mycart.php','_self')" class="button"></Td>
        </tr>
        <?
    } else {

        if (empty($_SESSION['loginid'])) {
            if (empty($_GET['errormsg'])) {
                $errormsg = "";
            } elseif ($_GET['errormsg'] == 1) {
                $errormsg = "<font color='red'>Invalid email or password</font>";
            }
            ?>
            <tr>
                <td width="35%" valign="top">

                    <font style="font-size:20px ">Please Sign In</font>
                    <br>

                    <br><br>
                    <form action="index.php" method="post" name="loginfrm">
                        <table width="100%" height="100%" class="solidborder" align="center">
                            <tr>
                                <td colspan="3"  class="table_header" align="center"><strong>Returning Customers: Please Log In</strong></td>
                            </tr>
                            <tr>
                                <TD width="13%" align="left" colspan="2">
                                    <?= $errormsg ?>
                                </td>
                            </tr>
                            <tr>
                                <td><strong>Email</strong></td>
                                <td width="87%"><input type="text" size="25" name="login_email" class="text"></td>
                            </tr>
                            <tr>	
                                <td><strong>Password</strong></td>
                                <td><input type="password" size="25" name="login_password" class="text"></td>
                            </tr>
                            <input type="hidden" name="fromBill" value="1">

                            <tr>
                                <td colspan="3">
                                    <div style="position: absolute; visibility: hidden;float:left" id="divForgotPwd"></div>
                                    <input type="submit" value="Login" class="button" name="loginsubmit"> &nbsp;  &nbsp;
                                    <input type="button" value="Forgot Password" class="button" onclick="showFloatContent('os_ajax_forgotpwd.php','divForgotPwd','500','50',0,500)">
                                    <br /><br />
                                    <? //<input type="button" value="Forgot my login details" class="button" onclick="windows.open('os_changepassword.php','_self)">  ?>
                                </td>
                            </tr>


                        </table>

                    </FORM>
                </td>


                <?
            }
            ?>

            <td width="65%" valign="top">
                <?
                if (empty($_SESSION['loginid'])) {
                    ?>
                    <font style="font-size:20px ">Or Register Now</font><br>
                    Create a login profile which allows you to shop faster, track the status of your current orders and review your previous orders.
                <? } ?> 

                <?
                if (empty($_SESSION['loginid'])) {
                    ?>
                    <br><br>
                    <form action="os_bill2.php" method="post" name="frm1" onSubmit="return formvalidate1(this)">
                        <table width="100%" height="100%" class="solidborder" align="center" >

                            <tr>
                                <td colspan="3"  class="table_header" align="center"><strong>Shopper Information Form</strong></td>
                            </tr>

                            <?
                        } else {
                            ?>	
                            <form action="os_bill2.php" method="post" name="frm1" onSubmit="return formvalidate2(this)">
                                <table width="100%" height="100%" align="center">
                                    


                                <? } ?>

                                <?
                                if (empty($_SESSION['loginid'])) {
                                    ?>
                                    <tr valign="top">
                                        <td width="20%">Email<font color="#FF0000">*</font></td>
                                        <td>:</td>
                                        <td width="70%">
                                            <input type="text" size="20" maxlength="80" name="email" id="email" onBlur="checkExist('email','divEmail','Email'); return false;">
                                            <br>Please enter a valid email address to receive the activation email.
                                            <div id="divEmail"></div>
                                        </td>
                                    </tr>
                                    <tr valign="top">
                                        <td>Password<font color="#FF0000">*</font></td><td>:</td><td><input type="password" size="20" maxlength="15" name="password"><br> Password length must be more than 6 characters (case sensitive).</td>
                                    </tr>
                                    <tr>
                                        <td>Confirm password<font color="#FF0000">*</font></td><td>:</td><td><input type="password" size="20" maxlength="15" name="cpassword"></td>
                                    </tr>
                                    <?
                                    if ($module_special_member == 1) {
                                        ?>
                                        <tr>
                                            <td>I would like to register as </td><td>:</td><td>
                                                <input type="radio" checked="checked" name="member_type" value="N"/> Normal User
                                                <input type="radio"  name="member_type" value="V" /> VIP (RM10 for registration fee)
                                            </td>
                                        </tr>
                                    <? } else { ?>
                                        <input type="hidden" name="member_type" value="N"/>
                                    <? } ?>
                                    <tr>

                                        <?
                                    } else {
                                        $errormsg = "";
                                        if (!empty($_GET['errormsg'])) {
                                            if ($_GET['errormsg'] == 3) {
                                                $errormsg = "<div class='dw_success'>Member registration successful. Proceed to next step to continue.</font>";
                                            }
                                        }
                                        ?>
                                    <tr>
                                        <td colspan="3"><?= $errormsg ?></td>
                                    </tr>
                                    <tr valign="top">
                                        <td>Email<font color="#FF0000">*</font></td><td>:</td><td><input type="text" size="20" maxlength="80" name="email"  value="<?= $email ?>">

                                        </td>
                                    </tr>
                                <? } ?>
                                <tr>
                                    <td width="20%">Name <font color="#FF0000">*</font></td>
                                    <td width="3">:</td>
                                    <td width="80%"><input type="text" class='text' size="30" maxlength="50" name="name" value="<?= $name ?>"></td>
                                </tr>
                                <input type="hidden" value="" name="membership_number">
                                </tr>
                                <tr>
                                    <td>Contact number<font color="#FF0000">*</font> </td><td>:</td><td><input type="text" class='text' size="20" maxlength="20" name="hpnumber" value="<?= $hpnumber ?>"><br></td>
                                </tr>
                                <tr>
                                    <td>Address <font color="#FF0000">*</font></td><td>:</td><td><input type="text" class='text' size="40" maxlength="100" name="address1" value="<?= $address1 ?>"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"></td><td><input type="text" class='text' size="40" maxlength="100" name="address2" value="<?= $address2 ?>"></td>
                                </tr>
                                <tr>
                                    <td>Postcode</td><td>:</td><td><input type="text" class='text' size="7" maxlength="15" name="postcode" value="<?= $postcode ?>"></td>
                                </tr>
                                <tr>
                                    <td>City</td><td>:</td><td><input type="text" class='text' size="20" maxlength="15" name="city" value="<?= $city ?>"></td>
                                </tr>

                                <tr valign="top">
                                    <td>Country</td><td>:</td>
                                    <td width="722">

                                        <?
                                        $get_place = mysql_query("select * from os_country where status=1 order by engname asc");
                                        ?>
                                        <select name="country" id="country" class="text" onChange="getAreaType(this.value)">
                                            <option value="">Please Selected</option>
                                            <?
                                            while ($s = mysql_fetch_array($get_place, MYSQL_ASSOC)) {
                                                if ($s['id'] == $country) {
                                                    $desslt = "selected";
                                                } else {
                                                    $desslt = "";
                                                }
                                                ?>
                                                <option value="<?= $s['id'] ?>" <?= $desslt ?>><?= $s['engname'] ?></option>
                                                <?
                                            }
                                            ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr valign="top">
                                    <td><div id="divAreaType">State / Province</div></td><td>:</td>
                                    <td>
                                        <div id="divState">
                                            <?
                                            $get_place = mysql_query("select * from os_state where country_id='" . $country . "' order by name_eng asc") or die(mysql_error());
                                            ?>
                                            <select name="state" id="state" class="text" onchange="getShipping(this.value)">
                                                <option value="">Please select</option>
                                                <?
                                                while ($s = mysql_fetch_array($get_place, MYSQL_ASSOC)) {
                                                    if ($s['id'] == $state) {
                                                        $sslt = "selected";
                                                    } else {
                                                        $sslt = "";
                                                    }
                                                    ?>
                                                    <option <?= $sslt ?> value="<?= $s['id'] ?>" ><?= $s['name_eng'] ?></option>
                                                    <?
                                                }
                                                ?>
                                            </select>
                                        </div>

                                    </td>
                                </tr>
                                <tr>
                                    <Td>Total Weight</td><Td>:</td><Td><?= getTotalWeight() ?> KG</td>
                                </tr>
                                <tr valign="top">
                                    <td>Shipping Service<font color="#FF0000">*</font></td><td>:</td>
                                    <td>
                                        <div id="divShippingCompany">
                                            <select name="service_preferred" id="service_preferred" class="text" onchange="getShipping()">
                                                <option value="">Please select</option>
                                                <option value="0" >Pick From Store</option>
                                                <?
                                                $get_shipping = mysql_query("SELECT a.id AS shipping_id, a.company_name, b.id AS rate_id, b.courier_id, b.country_id
																  FROM os_shipping_company a
																  INNER JOIN os_shipping_zone_country b ON a.id = b.courier_id
																  WHERE b.country_id = '$country'
																  GROUP BY a.id") or die(mysql_error());

                                                while ($s = mysql_fetch_array($get_shipping, MYSQL_ASSOC)) {
                                                    if ($service_preferred == $s['shipping_id']) {
                                                        $sslt = "selected";
                                                    } else {
                                                        $sslt = "";
                                                    }
                                                    ?>
                                                    <option value="<?= $s['shipping_id'] ?>" <?= $sslt ?>><?= $s['company_name'] ?></option>
                                                    <?
                                                }
                                                ?>									
                                            </select>
                                        </div>

                                        <div id="divShipping">
                                            <?
                                            if ($service_preferred != 0) {
                                                echo getShippingDesc($service_preferred, $country, $state);
                                            }
                                            ?>
                                        </div>

                                    </td>
                                </tr>                                           
                                <tr valign="top">
                                    <td>Remarks</td><td>:</td><td><textarea rows="5" cols="35" name="message" class="contentfont" ><?= $message ?></textarea></td>
                                </tr>
                                <?
                                if ($module_gift_voucher == 1) {
                                    if (!empty($_SESSION['loginid'])) {
                                        if (!empty($_SESSION['discount_voucher'])) {
                                            $discount_voucher = $_SESSION['discount_voucher'];
                                        } else {
                                            $discount_voucher = "";
                                        }
                                        ?>
                                        <tr valign="top">
                                            <td>Discount Voucher</td><td>:</td><td>
                                                <input type="text" class="text" size="10" value="<?= $discount_voucher ?>" maxlength="20" name="discount_voucher" id="discount_voucher" > 
                                                <input type="button" value="Validate Voucher" onclick="validateVoucher()" class="button" />
                                                <div id="divVoucher"></div>	
                                            </td>
                                        </tr>
                                        <?
                                    } else {
                                        ?>
                                        <input type="hidden" name="discount_voucher" value="" />
                                    <? }
                                } else { ?>
                                    <input type="hidden" name="discount_voucher" value="" />
                                <? } ?>
                                <tr valign="top">
                                    <Td>Security Check</Td>
                                    <td>:</td>
                                    <td>
                                        <script>
                                            var RecaptchaOptions = {
                                                theme : 'clean'
                                            };
                                            var RecaptchaOptions = {  
                                                theme : 'custom',  
                                                lang: 'en',  
                                                custom_theme_widget: 'divrecaptcha' //div enclosing widget elements  
                                            };  
                                        </script>

                                        <div id="divrecaptcha" style="display: none;">

                                            <div id="controls"><a href="#" onclick="Recaptcha.reload(); ">Get
                                                    another Captcha</a> <br />
                                            </div>

                                            <div id="recaptcha_image"></div>
                                            <!--Important-->

                                            <p><input type="text" name="recaptcha_response_field"
                                                      id="recaptcha_response_field" /><!--Important--> <br />
                                                <span class="recaptcha_only_if_image">Enter the words shown above
                                                    separated by space</span>

                                        </div>

                                        <?
                                        require_once('required/recaptchalib.php');

                                        echo recaptcha_get_html($captcha_key_public);
                                        ?>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3" align="center"><input type="submit" value="Submit" class="button" name="btnsubmit">

                                        <input type="reset" value="Reset" class="button">
                                    </td>
                                </tr>	

                                <?
                                if (empty($_SESSION['loginid'])) {
                                    $isnew = 1;
                                } else {
                                    $isnew = 0;
                                }
                                ?> 
                                <input type="hidden" value="<?= $isnew ?>" name="isnew">	


                            </table>
                        </form>
                        </td>
                        </tr>
                    <? } ?>
                </table>

                <? require("required/footer.php"); ?>